$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/usepayinfo/list',
        datatype: "json",
        colModel: [
			{ label: '手机号', name: 'mobile', index: 'mobile', width: 80 },
			{ label: '用户id', name: 'userId', index: 'user_id', width: 80, key: true },
			{ label: '支付宝账号', name: 'aliPayAccount', index: 'ali_pay_account', width: 80 },
			{ label: '支付宝姓名', name: 'aliPayName', index: 'ali_pay_name', width: 80 },
			{ label: '支付宝收款二维码', name: 'aliQrCode', index: 'ali_qr_code', width: 80 , formatter: function (value, options, row) {
                        return "<img  style='width:30px;height: 30px;cursor:pointer;'  src='"+value+"'   onclick='showImg(\""+value+"\")'/>";
                }
            },
			{ label: '微信账号', name: 'weixinPayAccount', index: 'weixin_pay_account', width: 80 },
			{ label: '微信收款二维码', name: 'wxQrCode', index: 'wx_qr_code', width: 80 ,formatter: function (value, options, row) {
                    return "<img  style='width:30px;height: 30px;cursor:pointer;'  src='"+value+"'   onclick='showImg(\""+value+"\")'/>";
                }
            },
			{ label: '开户银行名', name: 'bankName', index: 'bank_name', width: 80 },
			{ label: '开户行地址', name: 'bankAddress', index: 'bank_address', width: 80 },
			{ label: '银行卡号', name: 'bankAccount', index: 'bank_account', width: 80 },
			{ label: '开户人姓名', name: 'bankRealName', index: 'bank_real_name', width: 80 },
			{ label: '备注', name: 'remark', index: 'remark', width: 80 },
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{
            userId:null,
            mobile:null
        },
		showList: true,
		title: null,
		usepayInfo: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.usepayInfo = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
		},
        reset:function(){
            vm.q = {mobile:null};
            $("input[name='qInput']").val('');
            vm.reload();
        },
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.usepayInfo.id == null ? "sys/usepayinfo/save" : "sys/usepayinfo/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.usepayInfo),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "sys/usepayinfo/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(id){
			$.get(baseURL + "sys/usepayinfo/info/"+id, function(r){
                vm.usepayInfo = r.usepayInfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
            var parmas=	{'userId':vm.q.userId,'mobile':vm.q.mobile};
			$("#jqGrid").jqGrid('setGridParam',{
                postData:parmas,
                page:1
            }).trigger("reloadGrid");
		}
	}
});

function showImg(val){
    $("#showImg").attr("src",val);
    layer.open({
        type: 1,
        skin: 'layui-layer-molv',
        title: "收款码",
        area: ['650px', '500px'],
        shade: 0,
        shadeClose: false,
        content: jQuery("#Img"),
        btn: ['确定'],
        btn1: function (index) {
            layer.close(index);
        }
    });
}